if (FALSE) {
### Save code in a file "demo.r" and run with 2 processors by
### SHELL> mpiexec -np 2 Rscript demo.r
spmd.code <- "
### Initialize
suppressMessages(library(pbdMPI, quietly = TRUE))
### Examples.
if(comm.rank() == 0){
a <- c(T, F, NA)
} else{
a <- T
}
comm.any(a)
comm.all(a)
comm.any(a, na.rm = TRUE)
comm.all(a, na.rm = TRUE)
comm.allcommon(1:3)
if(comm.rank() == 0){
a <- 1:3
} else{
a <- 3:1
}
comm.allcommon.integer(a)
### Finish.
finalize()
"
# execmpi(spmd.code, nranks = 2L)
}
Run the code above in your browser using DataLab